<?php
class updateUser_model extends Model{
	
	 function updateUser_model()
	 {
	 	parent::Model();
	 }
	 
	 function update_askerMark($uid,$price)
	 {
 	 	$this->db->where('id',$uid);
 	 	$query = $this->db->get('ci_ask_user');
 	 	$result = $query->result();
 	 	$mark = $result[0]->mark;
 	 	$data = array( 'mark' => $mark - $price);
 	 	$this->db->where('id', $uid);
 	 	$this->db->update('ci_ask_user',$data) ;

	 }
	 
	 function update_replierAnswercount($uid)
	 {
	 	$this->db->where('id',$uid);
//	 	$this->db->join('ci_ask_user','ci_ask_user.id = ci_ask_answer.uid');
//	 	$query = $this->db->get('ci_ask_answer');
//	 	$result = $query->result();
		$this->db->select('answercount');
		$query = $this->db->get('ci_ask_user');
		$result = $query->result();
	 	$answercount = $result[0]->answercount + 1;
	 	$data = array('answercount' => $answercount);
 	 	$this->db->where('id',$uid);
	 	$this->db->update('ci_ask_user',$data);
	 }
	 
	 function update_replierMark($aid)
	 {
	 	$this->db->where('ci_ask_answer.id',$aid);
	 	$this->db->select('*,
	 						ci_ask_question.id as qid,
	 						ci_ask_answer.id as aid,
	 						ci_ask_user.id as uid');
		$this->db->join('ci_ask_user','ci_ask_user.id = ci_ask_answer.uid');
		$this->db->join('ci_ask_question','ci_ask_question.id = ci_ask_answer.qid');
		$query = $this->db->get('ci_ask_answer');
		$result = $query->result();
		$mark = $result[0]->mark;
		$price = $result[0]->price;
		$data = array( 'mark' => $mark + $price);
		$this->db->where('ci_ask_user.id',$result[0]->uid);
		$this->db->update('ci_ask_user',$data) ;
				
	 }
	 
	 function update_user_password($uid,$password_data)
	 {
	 	$this->db->where('id',$uid);
	 	$this->db->update('ci_ask_user',$password_data);
	 }
}
?>